package com.dongao.activity;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.dongao.model.Mp3Info;
import com.dongao.utils.FileUtil;

public class LocalCourseActivity extends ListActivity {
	private List<Mp3Info> mp3Infos = new ArrayList<Mp3Info>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_local_course);
		
	}
	
	@Override
	protected void onResume() {
		mp3Infos = FileUtil.getMp3Files("dongao/video/");

		List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		
		if (mp3Infos != null) {
			for (Mp3Info mp3 : mp3Infos) {
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("mp3_name", mp3.getMp3Name());
				map.put("mp3_size", mp3.getMp3Size());
				list.add(map);
			}
		}

		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				R.layout.mp3info_item, new String[] { "mp3_name", "mp3_size" },
				new int[] { R.id.mp3_name, R.id.mp3_size });
		
		setListAdapter(simpleAdapter);
		super.onResume();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Mp3Info info = mp3Infos.get(position);
		info.setUrl(FileUtil.getSDCardRoot()+File.separator+"androidmedie"+File.separator+info.getMp3Name());
		Intent intent = new Intent();
		intent.putExtra("mp3Info", info);
		intent.setClass(this, VideoActivity.class);
		startActivity(intent);
		super.onListItemClick(l, v, position, id);
	}
	
	
}
